package com.activemq.demo.activemq_service.controller;

import com.activemq.demo.activemq_service.model.MessageRequest;
import com.activemq.demo.activemq_service.model.MessageResponse;
import com.activemq.demo.activemq_service.service.MessageProducerService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/messages")
public class MessageController {

    @Autowired
    private MessageProducerService messageProducerService;

    @PostMapping
    public ResponseEntity<MessageResponse> sendMessage(@Valid @RequestBody MessageRequest messageRequest) {
        MessageResponse response = messageProducerService.sendMessage(messageRequest);

        if ("SENT".equals(response.getStatus())) {
            return ResponseEntity.ok(response);
        } else {
            return ResponseEntity.badRequest().body(response);
        }
    }

    @GetMapping("/health")
    public ResponseEntity<String> healthCheck() {
        return ResponseEntity.ok("ActiveMQ Service is running");
    }
}